home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 2D / FullScreen / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  4.7 KB  |  108 lines

  1. /*
  2.     File:        main.c
  3.  
  4.     Contains:    Sample code to demonstrate how to run an app in full screen mode on MacOS X
  5.  
  6.     Written by:     Karl Groethe    
  7.  
  8.     Copyright:    Copyright © 2000 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.             You may incorporate this Apple sample source code into your program(s) without
  11.             restriction. This Apple sample source code has been provided "AS IS" and the
  12.             responsibility for its operation is yours. You are not permitted to redistribute
  13.             this Apple sample source code as "Apple sample source code" after having made
  14.             changes. If you're going to re-distribute the source, we require that you make
  15.             it clear in the source that the code was descended from Apple sample source
  16.             code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                         8/25/00     Created
  20. */
  21. #include <Carbon/Carbon.h>
  22. #include <Quicktime/Quicktime.h>
  23.  
  24. pascal void CrazyXs(EventLoopTimerRef inTimer, void *inUserData);
  25. pascal OSStatus mySuspendResumeHandler(    EventHandlerCallRef inRef,
  26.                                                 EventRef inEvent,
  27.                                                 void* userData);
  28.  
  29. const RGBColor    backgroundColor={0,0,0};
  30.  
  31. int main(int argc, char* argv[])
  32. {
  33.     WindowRef         fullScreenWindow;
  34.     Ptr            oldState;
  35.     static EventTypeSpec suspendResumeEvent[2]={{kEventClassApplication,kEventAppActivated},
  36.                                                 {kEventClassApplication,kEventAppDeactivated}};
  37.     //Startup Full Screen Mode
  38.     BeginFullScreen(&oldState,nil,0,0,&fullScreenWindow,0,fullScreenAllowEvents);
  39.     //handle suspend and resume events so we don't mess up other apps
  40.     InstallApplicationEventHandler(NewEventHandlerUPP(mySuspendResumeHandler),2,
  41.                                     suspendResumeEvent,&fullScreenWindow,NULL);
  42.     // Call the event loop
  43.     RunApplicationEventLoop();
  44.     //we're done so put the screen back
  45.     EndFullScreen(oldState,nil);
  46.  
  47.     return 0;
  48. }
  49. pascal OSStatus mySuspendResumeHandler(    EventHandlerCallRef inRef,
  50.                                                 EventRef inEvent,
  51.                                                 void* userData)
  52. {
  53.     /*------------------------------------------------------
  54.         Carbon Event handler to handle when we swtich to a 
  55.         different application(cmd-tab)
  56.     --------------------------------------------------------*/
  57.     static EventLoopTimerRef myLoopTimer=NULL;
  58.     static EventTimerInterval Xdelay=kEventDurationSecond/4;
  59.     WindowRef fullScreenWindow=*((WindowRef*)userData);
  60.     Rect windowRect;
  61.     switch(GetEventKind(inEvent)){
  62.         //app has been activated so start Drawing
  63.         case kEventAppActivated:    ShowWindow(fullScreenWindow);
  64.                                         SetPortWindowPort(fullScreenWindow);
  65.                                         GetWindowPortBounds(fullScreenWindow,&windowRect);
  66.                                         RGBForeColor(&backgroundColor);
  67.                                         PaintRect(&windowRect);
  68.                                         //just to make it interesting
  69.                                         //each time the app switches, double the speed
  70.                                         Xdelay/=2;
  71.                                         //install Timer to handle drawing 
  72.                                         InstallEventLoopTimer(GetMainEventLoop(),
  73.                                                               0,Xdelay,
  74.                                                               NewEventLoopTimerUPP(CrazyXs),
  75.                                                               NULL,&myLoopTimer);
  76.                                         break;
  77.         //app has been deactivated so stop drawing
  78.         case kEventAppDeactivated:    HideWindow(fullScreenWindow);
  79.                                         RemoveEventLoopTimer(myLoopTimer);
  80.                                         break;
  81.     }
  82.     return noErr;
  83. }
  84.  
  85. pascal void CrazyXs(EventLoopTimerRef inTimer, void *inUserData)
  86. {
  87.     /*------------------------------------------------------
  88.         Here is where we draw and X on the screen
  89.     --------------------------------------------------------*/
  90.     const int kXSize=128;//make them big
  91.     CGrafPtr    drawingPort;
  92.     Rect     bounds;
  93.     RGBColor    randomColor={Random(),Random(),Random()};
  94.     short h,v;
  95.     TextSize(kXSize);
  96.     TextFont(kFontIDNewYork);
  97.     GetPort(&drawingPort);
  98.     GetPortBounds(drawingPort,&bounds);
  99.     RGBForeColor(&randomColor);
  100.     h=Random()%(bounds.right-bounds.left);
  101.     v=Random()%(bounds.bottom-bounds.top);
  102.     MoveTo(h,v);
  103.     //Draw our random colored X at a random location
  104.     DrawString("\pX");
  105. }
  106.  
  107.  
  108.